package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.UserRole;
import com.itheima.health.service.UserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("userRole")
public class UserRoleController {

    @DubboReference
    private UserRoleService userRoleService;

    @RequestMapping("findByUserId")
    public Result findByUserId(Integer id){
        List<UserRole> userRoleList = userRoleService.findById(id);
        List<Integer> ids = new ArrayList<>();
        for (UserRole userRole : userRoleList) {
           ids.add( userRole.getRoleId());
        }
        if (ids==null){
            return new Result(false, MessageConst.QUERY_ROLE_FAIL);
        }
        return new Result(true,MessageConst.QUERY_ROLE_SUCCESS,ids);
    }
}
